package pl.myszon.RILLib;

import java.util.List;

/**
 *
 * @author Myszon
 */
class ResponseParser {

    protected StatusCode parseStatusCode(Response response) {
        List resp = (List) response.headers.get("Status");

        String header = (String) resp.get(0);
        if(header.startsWith("200"))
            return StatusCode.OK;
        if(header.startsWith("400"))
            return StatusCode.INVALID_REQUEST;
        if(header.startsWith("401"))
            return StatusCode.USERNAME_AND_PASSWORD_INCORRECT;
        if(header.startsWith("403"))
            return StatusCode.RATE_LIMIT_EXCEEDED;
        if(header.startsWith("503"))
            return StatusCode.SERVER_IS_DOWN;

        return StatusCode.INVALID_REQUEST;
    }

    ServerAnswer parse(Response response) {
        return new ServerAnswer(parseStatusCode(response), null);
    };
}
